import java.util.Scanner;

//给定一个有序整型数组, 实现二分查找
public class BinarySearch {
    public static void main(String[] args) {
    int arr[]=new int [] {0,1,2,3,4,5,6,7,8,9};
        System.out.println("输入要查找的值：");
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        int left=0;
        int high=arr.length-1;
        int mid=(left+high)/2;
        while(left<=high){
            if(arr[mid]<n){
                left=mid+1;
                mid=(left+high)/2;
            }else if(arr[mid]>n){
                high=mid-1;
                mid=(left+high)/2;
            }else{
                System.out.println("找到，下标为："+mid);
                break;
            }
        }
        if(left>high){
            System.out.println("找不到！");
        }
    }
}
